<?php

namespace Backend\Models;

use Yii;
/**
 * "{{%user}}"表的模型类.
 *
 * @property int $id
 * @property string $username 用户名
 * @property string $nickname 昵称
 * @property int $gender 性别
 * @property string $avatar 头像
 * @property string $authKey 授权KEY
 * @property string $passwordHash 密码hash
 * @property string $passwordResetToken 密码重置token
 * @property string $verificationToken 邮件验证token
 * @property string $email 邮箱
 * @property string $mobile 手机
 * @property int $status 状态
 * @property string $loginAt 上次登陆时间
 * @property string $loginFailure 登陆失败消息
 * @property string $loginIp 登录IP
 * @property string $createdAt 添加时间
 * @property string $updatedAt 更新时间
 */
class User extends \DuAdmin\Core\BaseModel
{
    ///**
    // * 对象json序列化的时候设置不显示的字段
    // *
    // * @var array
    // */
    // public $jsonHideFields = [];

    // /**
    //  * 存储的数据是json的字段
    //  *
    //  * @var array
    //  */
    // public $jsonFields = [];
    
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%user}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['gender', 'status'], 'integer'],
            [['email'], 'email'],
            [['mobile'], 'mobile'],
            [['loginAt', 'createdAt', 'updatedAt'], 'safe'],
            [['username', 'nickname'], 'string', 'max' => 32],
            [['avatar', 'loginFailure'], 'string', 'max' => 255],
            [['authKey', 'passwordHash', 'passwordResetToken', 'verificationToken'], 'string', 'max' => 128],
            [['email', 'loginIp'], 'string', 'max' => 64],
            [['mobile'], 'string', 'max' => 16],
            [['username'], 'unique'],
            [['email'], 'unique'],
            [['mobile'], 'unique'],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app_user', 'ID'),
            'username' => Yii::t('app_user', 'Username'),
            'nickname' => Yii::t('app_user', 'Nickname'),
            'gender' => Yii::t('app_user', 'Gender'),
            'avatar' => Yii::t('app_user', 'Avatar'),
            'authKey' => Yii::t('app_user', 'Auth Key'),
            'passwordHash' => Yii::t('app_user', 'Password Hash'),
            'passwordResetToken' => Yii::t('app_user', 'Password Reset Token'),
            'verificationToken' => Yii::t('app_user', 'Verification Token'),
            'email' => Yii::t('app_user', 'Email'),
            'mobile' => Yii::t('app_user', 'Mobile'),
            'status' => Yii::t('app_user', 'Status'),
            'loginAt' => Yii::t('app_user', 'Login At'),
            'loginFailure' => Yii::t('app_user', 'Login Failure'),
            'loginIp' => Yii::t('app_user', 'Login Ip'),
            'createdAt' => Yii::t('app_user', 'Created At'),
            'updatedAt' => Yii::t('app_user', 'Updated At'),
        ];
    }

    /**
     * {@inheritdoc}
     * @return UserQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new UserQuery(get_called_class());
    }

    ///**
    // * 默认开启所有操作的事务
    // * ```php
    // * return [
    // *     'admin' => self::OP_INSERT,
    // *     'api' => self::OP_INSERT | self::OP_UPDATE | self::OP_DELETE,
    // *     // the above is equivalent to the following:
    // *     // 'api' => self::OP_ALL,
    // *
    // * ];
    // * ```
    // */
    //public function transactions()
    //{
    //    return [
    //        self::SCENARIO_DEFAULT => self::OP_ALL
    //    ];
    //}
}
